//
//  NYMineOrderCell.m
//  NYTYY
//
//  Created by MinLison on 2017/12/8.
//  Copyright © 2017年 NYtyy. All rights reserved.
//

#import "NYMineOrderCell.h"

@interface NYMineOrderCell ()
@property(nonatomic, strong) QMUIGridView *gridView;
@end

@implementation NYMineOrderCell

- (void)configure
{
        [super configure];
        self.accessoryType = UITableViewCellAccessoryNone;
        NSArray <NSString *>*namesArray = @[@"星星榜",@"我的消息"];
        NSArray <UIImage *>*imagesArray = @[[UIImage shou_cang],[UIImage xiao_xi]];
        NSArray <NSString *>*urisArray = @[kNYMyStarRankingURI,kNYMyMessageURI];
        @weakify(self);
        [namesArray enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                QMUIButton *btn = [self createButtonForTitle:obj image:imagesArray[idx] actionBlock:^(NSInteger tag) {
                        @strongify(self);
                        if (self.actionBlock)
                        {
                                self.actionBlock(tag);
                        }
                        else
                        {
                                [NYUserManager pushOrPresentLoginIfNeed:YES inViewController:self.formViewController completion:^{
                                        
                                } dismiss:^{
                                        if (NYUserManager.isLogin) {
                                                [self.formViewController routeUrl:urisArray[idx] param:nil];
                                        }
                                }];
                        }
                }];
                btn.tag = idx;
                [self.gridView addSubview:btn];
        }];
        [self.contentView addSubview:self.gridView];
        [self.contentView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(self);
        }];
        [self.gridView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(self.contentView);
        }];

}
- (void)update
{
        [super update];
}
- (QMUIGridView *)gridView
{
        if (_gridView == nil) {
                _gridView = [[QMUIGridView alloc] init];
                _gridView.separatorWidth = __WGWidth(0);
                _gridView.separatorColor = [UIColor clearColor];
                _gridView.rowHeight = __WGHeight(55);
                _gridView.columnCount = 2;
        }
        return _gridView;
}
- (QMUIButton *)createButtonForTitle:(NSString *)title image:(UIImage *)image actionBlock:(void (^)(NSInteger tag))actionBlock
{
        QMUIButton *button = [[QMUIButton alloc] init];
        [button setTitle:title forState:(UIControlStateNormal)];
        [button setImage:image forState:(UIControlStateNormal)];
        [button jk_addActionHandler:actionBlock];
        button.imagePosition = QMUIButtonImagePositionLeft;
        button.spacingBetweenImageAndTitle = 8;
        [button setTitleColor:UIColorHex(0x323232) forState:(UIControlStateNormal)];
        button.titleLabel.font = WGSystem12Font;
        return button;
}
@end
